home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / vpe_130 / pascal / vpedemo.pas < prev   
Pascal/Delphi Source File  |  1996-09-15  |  51KB  |  1,712 lines

  1. {$A+,B-,D-,F-,G+,I-,K+,L-,N-,P-,Q-,R-,S-,T-,V-,W-,X+,Y-}
  2. {$M 8192,8192}
  3.  
  4. {
  5. //              VPEDEMO.PAS
  6. //              ===========
  7. //
  8. // Demonstration of VPE
  9. //
  10. // 12/1995 by IDEAL Software, T. Radde
  11. //}
  12. program VPEDEMO;
  13.  
  14. uses WinTypes,WinProcs,
  15.       {$IFDEF VER80} {Units for Delphi}
  16.        SysUtils,
  17.        Messages,
  18.       {$ELSE}
  19.        Strings,      {Units for BP7}
  20.       {$ENDIF}
  21.       VPEngine;
  22.  
  23.  
  24.  
  25. {----------------------------------------------------------------------------
  26. // Globals:
  27. //----------------------------------------------------------------------------
  28. }
  29.  
  30. {$R VPEDEMO.RES}
  31. var hMainWindow     : HWND;
  32. var hMainDlg        : HWND;
  33.  
  34. const Precision     : LongInt = 0;
  35. const PBackGnd     : LongInt = 0;
  36. const Speed         : LongInt = 0;
  37. const Colors         : LongInt = 0;
  38. const Report         : LongInt = 0;
  39.  
  40.  
  41. var DemoText : array [0..1024] of char;
  42.  
  43. procedure SetDemoText;
  44. begin
  45. StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(StrCopy(
  46. DemoText,'[PS 3 S 12 C Black J BO]The moment of impact bursts through the silence and in a roar of sound, the '),
  47. 'final second is prolonged in a world of echoes as if concrete and clay of '),
  48. 'Broadway itself was reliving its memories.'+#13+#10),
  49. 'The last great march past. Newsman stands limp as a whimper as audience and '),
  50. 'eventare locked as one. Bing Crosby coos''You don''t have to feel pain '),
  51. 'to sing the blues, you don''t have to holla - you don''t feel a thing in your '),
  52. 'dollar collar.'' Martin Luther cries ''Everybody Sing!'' and rings the grand old '),
  53. 'liberty bell. Leary, weary of his prison cell, walks on heaven, talks on hell.'+#13+#10),
  54. 'Who needs Medicare and the 35c flat rate fare, when Fred Astaire and '),
  55. 'Ginger Rogers are dancing through the air? From Broadway Melody stereotypes '),
  56. 'the band returns to ''Stars and Stripes'' bringing a tear to the moonshiner, '),
  57. 'who''s been pouring out his spirit from the illegal still. The pawn broker '),
  58. 'clears the noisy till and clutches his lucky dollar bill.'+#13+#10),
  59. 'Then the blackout.'+#13+#10+#13+#10),
  60. '(Genesis, ''The Lamb lies down on Broadway'')');
  61.  
  62. end;
  63.  
  64.  
  65. {//----------------------------------------------------------------------------
  66. //                               Precision
  67. //----------------------------------------------------------------------------
  68. }
  69. const HEADLINE = 1;      { ordinal for storing a setting}
  70.  
  71.  
  72. {// Page 1 of Precision demo
  73. // ========================
  74. }
  75. procedure page1(hDoc : LongInt);
  76. var y : Integer;
  77. var WYSIWYG : array[0..512] of char;
  78. begin
  79.    StrCat(StrCat(StrCat(StrCat(StrCat(StrCat(strcopy(WYSIWYG,
  80.    '[Center PenSize 3]This demo shows the capabilities and precision of VPE.'+#13+#10),
  81.    'Print this page and compare not only the '),
  82.    'positions of the frames,'+#13+#10+'but the positions of each letter that can be seen.'+#13+#10),
  83.    '(Switch the grid on.)'+#13+#10),
  84.    'This is true WYSIWYG !!!'+#13+#10+'(''What you see is what you get'')'+#13+#10),
  85.    'Note, that the nearest result can be seen at a scaling of 1:1.'+#13+#10),
  86.    'With every other scaling you get ''best results'' in comparison to execution speed.');
  87.    y := VpeWriteBox(hdoc, 575, 200, 1625, -1,WYSIWYG);
  88.    
  89.    y := VpeWriteBox(hdoc, 100, y + 75, 2000, -1,
  90.    '[''Arial'' FontSize 14 Left Bold Italic Underline PenSize 0]'+
  91.    'RIGHT ALIGNED, 0.25 cm blue frame, light-blue backgr., red bold text, Arial 9pt');
  92.    VpeStoreSet(hdoc, HEADLINE);
  93.    
  94.    VpeSelectFont(hdoc, 'Arial', 9);
  95.    VpeSetPen(hdoc, 25, PS_SOLID, COLOR_BLUE);
  96.    VpeSetTextColor(hdoc, COLOR_LTRED);
  97.    VpeSetFontAttr(hdoc, ALIGN_RIGHT, 1, 0, 0);
  98.    VpeSetTransparentMode(hdoc, 0);
  99.    VpeSetBkgColor(hdoc, COLOR_CYAN);
  100.    { y+30 because frame = 0.25cm --> frame drawn around center of coordinates
  101.    // we also want a little gap between the headline and the frame}
  102.    y := VpeWriteBox(hdoc, 150, y + 30, 1850, -1, DemoText);
  103.    VpeSetTransparentMode(hdoc, 1);
  104.  
  105.    VpeUseSet(hdoc, HEADLINE);
  106.    y := VpeWrite(hdoc, 250, y + 75, 2000, -1, 'JUSTIFIED, no frame, Times New Roman 11pt');
  107.  
  108.    VpeSelectFont(hdoc, 'Times New Roman', 11);
  109.    VpeSetFontAttr(hdoc, ALIGN_JUSTIFIED, 0, 0, 0);
  110.    y := VpeWriteBox(hdoc, 250, y + 20, 1550, -1, DemoText);
  111.  
  112.    VpeUseSet(hdoc, HEADLINE);
  113.    y := VpeWriteBox(hdoc, 250, y + 75, 2000, -1, 'CENTERED, thin yellow frame, Times New Roman 11pt');
  114.    
  115.    VpeSelectFont(hdoc, 'Times New Roman', 11);
  116.    VpeSetFontAttr(hdoc, ALIGN_CENTER, 0, 0, 0);
  117.    VpeSetPen(hdoc, 5, PS_SOLID, COLOR_LTYELLOW);
  118.    y := VpeWriteBox(hdoc, 150, y + 20, 1850, -1, DemoText);
  119. end;
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128. {// Page 2 of Precision demo
  129. // ========================
  130. }
  131. procedure page2(hDoc : LongInt);
  132.  
  133. type PtArray = array[0..3 * 1500] of TPoint;
  134.  
  135. var y : Integer;
  136. var xr,yr,x,xstep : real;
  137. var s : array[0..159] of char;
  138. var index, skip, first, xx, oldy : Integer;
  139. const segments : Integer =0;
  140. var p : LongInt;
  141. var points : ^PtArray;
  142. begin
  143.    VpePageBreak(hdoc);
  144.    VpeUseSet(hdoc, HEADLINE);
  145.    y := VpeWriteBox(hdoc, 200, 200, 2000, -1, 'An example of drawing (better to turn the grid off here):');
  146.    VpeSetPen(hdoc, 8, PS_SOLID, COLOR_BLACK);
  147.    VpeBox(hdoc, 200, 300, 1700, 1800);
  148.    VpeSetPen(hdoc, 3, PS_SOLID, COLOR_BLACK);
  149.  
  150.    xr := 6; xstep := xr / 750;
  151.    yr := 18;
  152.  
  153.    {// The following graph is created with VpeAddPolyPoint()}
  154.    x := -xr;
  155.    skip := 0;
  156.    VpeSetPen(hdoc, 2, PS_SOLID, COLOR_BLUE);
  157.    p := VpePolyLine(hdoc, 0, 1500);
  158.         
  159.    for xx := 200 to 1700-1 do
  160.    begin
  161.       y := Round(1050 - ((x*x*x) - 2*(x*x) - 8*x) / ( yr / 750));
  162.  
  163.       x := x + xstep;
  164.  
  165.       if (y < 300) then
  166.       begin
  167.          y := 300;
  168.          skip := 1;
  169.          continue;
  170.       end
  171.       else if (y > 1800) then
  172.       begin
  173.          y := 1800;
  174.          skip := 1;
  175.          continue;
  176.       end;
  177.  
  178.       if (skip = 1) then
  179.       begin
  180.          VpeAddPolyPoint(hdoc, p, -1, -1);
  181.          oldy := y;
  182.          skip := 2;
  183.       end
  184.       else
  185.       begin
  186.          if (skip = 2) then
  187.          begin
  188.             VpeAddPolyPoint(hdoc, p, xx-1, oldy);
  189.             skip := 0;
  190.          end;
  191.          VpeAddPolyPoint(hdoc, p, xx, y);
  192.          inc(segments);
  193.       end;
  194.    end;
  195.  
  196.  
  197.  
  198.    {// The following graph is created directly with VpePolyLine()}
  199.    New(Points);
  200.    x := -xr;
  201.    first := 1;
  202.    VpeSetPen(hdoc, 2, PS_SOLID, COLOR_LTRED);
  203.    index := 0;
  204.    for xx := 200 to 1700-1 do
  205.    begin
  206.       y := Round(1050 - (3*(x*x) - 4*x - 8) / ( yr / 750));
  207.       x := x+xstep;
  208.  
  209.       if (y < 300) then
  210.       begin
  211.          y := 300;
  212.          skip := 1;
  213.          continue;
  214.       end
  215.       else if (y > 1800) then
  216.       begin
  217.          y := 1800;
  218.          skip := 1;
  219.          continue;
  220.       end;
  221.  
  222.       if (skip = 1) then
  223.       begin
  224.          if (index > 0) then   {// Array must not begin with -1,-1 pair!}
  225.          begin
  226.             points^[index].x := -1;
  227.             points^[index].y := -1;
  228.          end;
  229.          {// don't increment index here, so we don't have multiple
  230.          // (redundant AND FORBIDDEN) -1, -1 pairs in the array}
  231.          oldy := y;
  232.          skip := 2;
  233.       end
  234.       else
  235.       begin
  236.          if (skip = 2) then
  237.          begin
  238.             if (index > 0) then
  239.                inc(index);
  240.             points^[index].x := xx - 1;
  241.             points^[index].y := oldy;
  242.             inc(index);
  243.             skip := 0;
  244.          end;
  245.          points^[index].x := xx;
  246.          points^[index].y := y;
  247.          inc(index);
  248.          inc(segments);
  249.       end;
  250.    end;
  251.  
  252.    VpePolyLine(hdoc, LongInt(points), index);
  253.    Dispose(points);
  254.  
  255.  
  256.  
  257.    {// The following graph is created "manually" VpeLine()
  258.    // Never use it for such tasks, it's slow and memory exhausting
  259.    // in comparision to VpePolyLine()}
  260.    x := -xr;
  261.    first := 1;
  262.    VpeSetPen(hdoc, 2, PS_SOLID, COLOR_GREEN);
  263.    for xx := 200 to 1700-1 do
  264.     begin
  265.       y := Round(1050 - (3*x - 4) / ( yr / 750));
  266.       x :=x+ xstep;
  267.  
  268.       if (y < 300) then
  269.       begin
  270.          y := 300;
  271.          first := 1;
  272.          continue;
  273.